if exists (select 1
            from  sysobjects
           where  id = object_id('bd_view_kq_holidays_time')
            and   type = 'V')
   drop view bd_view_kq_holidays_time
go

/*==============================================================*/
/* View: bd_view_kq_holidays_time                               */
/*==============================================================*/
create view bd_view_kq_holidays_time as
SELECT ht.id, ht.user_serial, ht.user_dept, ht.time_year, ht.time_month, CAST(ht.save_ordinary / 60.0 AS decimal(8,2)) save_ordinary, CAST(ht.save_weekend / 60.0 AS decimal(8,2)) save_weekend, 
  CAST(ht.owe / 60.0 AS decimal(8,2)) owe, CAST(ht.vacation_annual / 60.0 AS decimal(8,2)) vacation_annual, CAST(ht.vacation_lactational / 60.0 AS decimal(8,2)) vacation_lactational, 
  CAST(ht.rest_total / 60.0 AS decimal(8,2)) rest_total, ht.operate_id, ht.operate_time, u.user_no, u.user_lname user_name, u.user_dep, u.dep_name, op.user_no operate_no, op.user_lname operate_name,
  row_no = ROW_NUMBER() OVER (PARTITION BY ht.user_serial ORDER BY time_year, time_month DESC)
FROM bd_kq_holidays_time ht
INNER JOIN bd_view_user_all u ON u.user_serial = ht.user_serial
INNER JOIN (
    SELECT
      user_serial, user_no, user_lname, user_dep, dep_name
    FROM bd_view_user_all
  ) op ON op.user_serial = ht.operate_id
go
